package com.hundredhealth.rose.delegate;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.hundredhealth.rose.R;
import com.hundredhealth.rose.service.GPSTracker;
import com.kymjs.frame.view.AppDelegate;

/**
 * Created by huazhong on 26/6/2017.
 */

public class MainDelegate extends AppDelegate {

    private TextView activityDateView;
    private TextView activityLocationView;
    private TextView activityVendorNameView;
    private Intent gpsIntent;

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        activityDateView = (TextView) get(R.id.activityDate);
        activityVendorNameView = (TextView) get(R.id.companyName);
        activityLocationView = (TextView) get(R.id.locationTextView);
        gpsIntent = new Intent(getActivity(), GPSTracker.class);
        updateActivityInfo("------", "------", "活动地址正在努力获取中...");
    }

    public void updateActivityInfo(String date, String vendorName, String location) {
        activityDateView.setText(date);
        activityVendorNameView.setText(vendorName);
        activityLocationView.setText(location);
    }

    public void startGPSService() {
        if (gpsIntent != null)
            getActivity().startService(gpsIntent);
    }

    public void stopGPSService() {
        if (gpsIntent != null)
            getActivity().stopService(gpsIntent);
    }
}
